package com.ruoyi.system.interceptor;

import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.http.body.StringRequestBody;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.utils.ForestDataType;
import com.dtflys.forest.utils.RequestNameValue;
import com.ruoyi.system.domain.Forest.grm.AuthGRM;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

public class GRMAuthInterceptor implements Interceptor<Object> {

    @Override
    public void onSuccess(Object data, ForestRequest request, ForestResponse response) {
        String dataStr = response.getContent();
        //使用换行符分隔
        String[] split = dataStr.split("\r\n");
        if (split.length == 3){
            AuthGRM authGRM = new AuthGRM();
            if (split[0].equals("ERROR")){
                authGRM.setCode(1);
            } else {
                authGRM.setAddr(split[1].split("=")[1]);
                authGRM.setSid(split[2].split("=")[1]);
                authGRM.setCode(0);
            }
            response.setResult(authGRM);
        }
        Interceptor.super.onSuccess(data, request, response);
    }
}
